<!-- 冲账弹框-->
<template>
  <div>
    <!-- <Alert type="error">
      <h5>SellOrder.js文件中的扩展SellOrder表的头部信息,你可以在此处定义需要显示的信息,如果需要获取界面的Vue对象属性,参照此扩展组件GridHeaderExtend.vue的说明</h5>
    </Alert> -->
    <!--点击扩展按钮对应的弹出框-->
    <vol-box :model.sync="model" title="冲账" :width="650" :height="430">
      <VolForm
        ref="myform"
        :loadKey="loadKey"
        :formFileds="formFileds"
        :formRules="formRules"
        :labelWidth="140"
      ></VolForm>
      <!-- 添加slot槽覆盖footer的按钮，添加新的按钮 -->
      <div slot="footer">
        <Button type="success" @click="getFirstRow">保存</Button>
        <Button type="info" @click="close">关闭</Button>
      </div>
    </vol-box>
  </div>
</template>
<script>
import bus from "@/utilities/bus.js";
import VolForm from "@/components/basic/VolForm.vue";
export default {
  components: {
    VolBox: () => import("@/components/basic/VolBox.vue"),
    VolForm,
  },
  data() {
    return {
      abc: {}, //接收数据

      loadKey: true,
      model: false,
      formFileds: {
        account_name: "", //应收帐户名称(表格)
        // account_code: "", //应收账户编号
        account_alias: "", //应收账户编号（需修改）
        ptype_func: null, //功能类型 (表格数据)（需修改）
        pcreateDate: "", //入账日期 (表格数据)（需修改）

        type_func: 4, //功能类型（入账(11 充值 12消费 13 退款)，2-转账，3-调整，4-冲账）
        type_record: 3, //入账类型（1-渠道挂账，2-自动挂账，3-手工挂账，4-第三方挂账）
        notes: "", //冲账备注
        creator: "", //操作人
      },
      formRules: [
        //两列的表单，formRules数据格式为:[[{},{}]]
        [
          {
            title: "应收账户名称",
            field: "account_name",
            type: "text",
            disabled: true,
            colSize: 6,
          },

          {
            title: "应收账户编号",
            field: "account_alias", //需修改
            type: "text",
            disabled: true,
            colSize: 6,
          },
        ],

        [
          {
            title: "凭证号",
            field: "out_order_id",
            type: "text",
            disabled: true,
            colSize: 6,
          },

          {
            title: "功能类型",
            field: "ptype_func",
            type: "text",
            disabled: true,
            colSize: 6,
          },
        ],
        [
          {
            title: "入账日期",
            field: "pcreateDate",
            type: "text",
            disabled: true,
            colSize: 6,
          },
        ],
        // [{ title: "序号", field: "id", type: "text", disabled: true }],
        [
          {
            required: true, //是否必填
            title: "备注",
            field: "notes", //字段，与表单字段必须相同
            type: "textarea", //标签类型
            colSize: 12, //每行列的宽度，可选值:12,8,6,如果是12标签会占100%宽度
            min: 2,
          },
        ],
      ],
    };
  },
  methods: {
    // 传递数据
    transferData(row) {
      this.formFileds.ptype_func =
        row.type_func == 11
          ? "充值"
          : row.type_func == 12
          ? "消费"
          : row.type_func;
      this.formFileds.out_order_id = row.out_order_id;
      this.formFileds.pcreateDate = row.createDate;

      this.abc = row;
      console.log("接受数据 ", row, this.formFileds);
    },
    // 保存按钮
    getFirstRow() {
      this.$refs.myform.validate((result) => {
        if (result) {
          let params = { ...this.abc, ...this.formFileds };
          console.log("保存", params);
          if (sessionStorage.getItem("user")) {
            this.formFileds.creator = JSON.parse(
              sessionStorage.getItem("user")
            ).userName;
          }
          this.http
            .post("/api/AccountsDetail/AccountsDetailSet", params, true)
            .then((x) => {
              console.log("kk", x);
              if (!x.status) return this.$message.error(x.message);
              this.$message.success("操作成功");
              this.model = false;
              bus.$emit("refresh", "abc");
              this.$emit("refreshTables");
            });
        }
      });

      //this.$message.error();
      //   this.$emit("parentCall", $vue => {
      //     let rows = $vue.$refs.table.rowData;
      //     this.$message.error(
      //       rows.length == 0 ? "表格没有数据" : JSON.stringify(rows[0])
      //     );
      //此于拿到的$vue你可以操作其中的任何对象，如:
      //props.js中的属性，this.columns/this.editFormFileds
      //或者操作其他动态扩展的组件如:$vue.$refs.gridBody/$vue.$refs.gridFooter
      //$vue.$refs.table获取表格信息
      //$vue.refresh()刷新表格等操作
      //能操作的所有对象可参照props.js与ViewGird.uve的属性
      //能操作的方法methods.js/detailMethods.js
      //   });
    },
    close() {
      this.model = false;
      // let that = this.$store.getters.data().viewPageTest;
      // that.$refs.table.load();
    },
    // 重置表单
    resetForm() {
      this.$refs.myform.reset();
    },
  },
  created() {},
};
</script>
